package controllers

import (
	"github.com/astaxie/beego/logs"
	"github.com/gin-gonic/gin"
	"github.com/shenyisyn/goft-gin/goft"
	"sinery.net.goft/src/common"
	"sinery.net.goft/src/dao"
	"sinery.net.goft/src/models"
	"sinery.net.goft/src/services"
)

type TestController struct {
	Ctl *CommonController `inject:"-"`
	//User *models.UserModel `inject:"-"`
	Tvc         *services.TestService `inject:"-"`
	XormAdapter *dao.XormAdapter      `inject:"-"`
}

func NewTestController() *TestController {
	return &TestController{}
}

// 20210728171129
// http://localhost:8080/v1/sim
//[
//{
//"ctime": "1602637514",
//"id": "1",
//"notice_context": "cccc",
//"notice_title": "开业公告222"
//}
//]
func (t *TestController) SimpleQuey(ctx *gin.Context) goft.SimpleQuery {
	return "select * from kc_notice_context limit 1"
}
func (t *TestController) SimpleWithArgs(ctx *gin.Context) goft.Query {
	simp := goft.SimpleQuery("select * from kc_notice_context where id=? limit 1").
		WithArgs("1").
		WithMapping(map[string]string{"id": "uid"}).
		WithFirst().
		WithKey("ctime")
	logs.Info(simp.Sql())
	logs.Info(simp.Mapping())
	logs.Info(simp.Get())
	logs.Info(simp.Key())
	return simp
}
func (t *TestController) Index(ctx *gin.Context) goft.Json {
	res := t.Tvc.GetUserinfo()
	m := &models.NoticeContextModel{}
	l, err := t.XormAdapter.Engine.
		Select("*").
		Where("id = ?", 1).
		Get(m)
	if err != nil {
		logs.Info("err: %s", err.Error())
	}
	logs.Info("res: %v", l)
	logs.Info("%+v", m)
	//panic(common.Error(_const.BUS_COMPANYNAME_NIL,"msg"))
	return common.Success(map[string]interface{}{"res": res})
}

//这里声明一下models value
//这里是不需要在全局内存进行注册的 全局组件包括 数据库组件 缓存组件 代理组件 orm组件
//常驻内存的redis组件 订单uuid组件 tragger组件
//agent收集组件
//master-woker-tasker
//logger
//oss
//image
//
